import sun.misc.Launcher;

import java.net.URL;
import java.net.URLClassLoader;

public class TestHashSet {
    public static void main(String[] args) {
        ClassLoader classLoader = Object.class.getClassLoader();
        System.out.println(classLoader);
        //查看引导类加载器会加载那些jar包
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL urL : urLs) {
            System.out.println(urL);
        }
        ClassLoader parent = ClassLoader.getSystemClassLoader().getParent();
        // 确保我们获取的是ExtClassLoader实例,因为ExtClassLoader继承了URLClassLoader
        if (parent instanceof URLClassLoader) {
            // 强制转换为URLClassLoader以访问getURLs()方法
            URLClassLoader urlClassLoader = (URLClassLoader) parent;
            URL[] urls = urlClassLoader.getURLs();
            // 打印ExtClassLoader加载的目录
            System.out.println("ExtClassLoader加载的目录如下:");
            for (URL url : urls) {
                System.out.println(url.getFile());
            }
        } else {
            System.out.println("无法获取ExtClassLoader的加载路径，因为它的类型不是URLClassLoader");
        }
    }
}
